For LScript's C-like syntax, the following keywords and operators are used:
if else while pragma var break switch case library const continue return True/true False/false Nil/nil = + - * / == != <= >= += -= *= /= ++ -- || && ! % & ^ << >> |= ^= &=LScript also allows you to use AREXX-like keywords in constructing your scripts:
begin end then do to select when byExamples of this alternate syntax can be found in the LScript example script file2.ls.
jitter(1.5); // make it uniformly uglyAlternatively, multiple lines can be commented using the C- standard '/*' '*/' token pair:
/* multiple lines of comments */
if((f.eof() == false) && (size(tokens) > 1) && (tokens[1] == "Plugin")) info(tokens[1]," ",tokens[2]);The second style is similar to AREXX:
if f.eof() == false and size(tokens) > 1 and tokens[1] == "Plugin" then info(tokens[1]," ",tokens[2]));If operators that host more than one executable statement must house those statements inside a block control, identical in structure to that used by user-defined procedures.
if(file == nil) { error("Cannot create scene file ",sceneFile); return; }or, alternately,
if file == nil then begin error("Cannot create scene file ",sceneFile); return; endIf operators can facilitate "either/or" situations through the use of an else clause. The else clause follows the executable statement (or block control) for the if operator:
if(lensFlare[index]) { file.writeln("LensFlare 1"); ... } else file.writeln("LensFlare 0");
while ( /boolean expression/ ) /statement/As with if, LScript also allows the script programmer to use an alternate syntax for while that is similar to AREXX:
while /boolean expression/ do begin ... endThere are two LScript commands that allow the script programmer to effect the flow of looping controls: break and continue. Each of these commands are discussed in sections found later in this document.
for ( /init/ ; /expr/ ; /post/ ) /statement/LScript also allows this simpler, AREXX-like form of the for operator:
for /var/ = /expr/ to /expr/ [ by /expr/ ] do begin ... endIn either format, any variables used by the for loop operator must have been previously declared before being used.
switch ( /expression/ ) { case /number/ : ... break; default: ... break; }Again, LScript offers an AREXX-like version of this selection mechanism through the use of the select operator. However, unlike the switch operator, whose selection criteria is limited solely to numeric values, the select control allows whole expressions to be evaluated in determining the code to execute:
select when /expression/ then do ... end end
/boolean expression/ ? /true select/ : /false select/This operator can be use just about anyplace an expression can appear in LScript. For example,
main { j = 1; ... info("result is ",(j == 1 ? "yes" : "no")); }
Consider the following example:
while(j) { if(j == 10) break; // line 4 ++j; } info("j == ", j); // line 9In the preceding example, upon encountering the break in line #4, LScript would cause the while loop to terminate, and would set its internal program counter to the executable statement on line #9 (info()).
In the case of while, the condition upon which the control loop is based is once again evaluated, and program execution continues from there.
In the case of a for loop, the post-loop code is evaluated, and the condition upon which the control loop is based is re- evaluated. Program execution continues from that point.
while(1) continue; // uh oh! an infinite loop!